package com.coding.service;

import com.coding.utils.Constant;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

/**
 * @author Cynicism
 * @version 1.0
 * @project DyApp
 * @description
 * @date 2024/7/11 11:03:26
 */
@Service
@RocketMQMessageListener(topic = "like-topic", consumerGroup = "like-consumer-group")
@Slf4j
public class LikeConsumer implements RocketMQListener<String> {

    @Autowired
    private StringRedisTemplate redisTemplate;

    @Override
    public void onMessage(String liveStreamId) {
        String key = Constant.REDIS_LIKE_KEY_PREFIX + liveStreamId;
        redisTemplate.opsForValue().increment(key);
        log.info("消费点赞事件: {}", liveStreamId);
    }
}
